package com.lifeng.mynetty.response;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Cache {
    private static final Cache cache = new Cache();
    private static final Map<String, ResponseCallBack> CALLBACK_CACHE = new ConcurrentHashMap<String, ResponseCallBack>();

    private Cache(){
    }

    public static Cache getInstance(){
        return cache;
    }

    public void putCallback(String key, ResponseCallBack callback){
        CALLBACK_CACHE.put(key, callback);
    }

    public ResponseCallBack getCallback(String key){
        if (CALLBACK_CACHE.containsKey(key)){
            return CALLBACK_CACHE.get(key);
        } else {
            return null;
        }
    }

    public ResponseCallBack removeCallback(String key){
        if (CALLBACK_CACHE.containsKey(key)){
            return CALLBACK_CACHE.remove(key);
        } else {
            return null;
        }
    }
}
